package com.jpl.demo.mobility.ui.util;

import com.vaadin.Application;
import com.vaadin.service.ApplicationContext;
import com.vaadin.terminal.gwt.server.WebApplicationContext;
import com.vaadin.terminal.gwt.server.WebBrowser;

public class BroswerInfoHelper {

	private static final String ANDROID = "Android";
	private static final String IPHONE = "iPhone";

	public static boolean isMobile(Application application) {
		return isAndroid(application) || isIPhone(application);
	}

	public static boolean isAndroid(Application application) {
		boolean result = false;

		if (application != null) {
			ApplicationContext context = application.getContext();
			WebBrowser browser = ((WebApplicationContext) context).getBrowser();
			String browserApplication = browser.getBrowserApplication();
			if (browserApplication != null
					&& browserApplication.contains(ANDROID)) {
				result = true;
			}
		}
		return result;
	}

	public static boolean isIPhone(Application application) {
		boolean result = false;

		if (application != null) {
			ApplicationContext context = application.getContext();
			WebBrowser browser = ((WebApplicationContext) context).getBrowser();
			String browserApplication = browser.getBrowserApplication();
			if (browserApplication != null
					&& browserApplication.contains(IPHONE)) {
				result = true;
			}
		}

		return result;
	}

}
